/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package flight.model;

import java.util.List;
import middleware.MutableInteger;
import middleware.Serializable;
import middleware.Serialization;


/**
 *
 * @author tam
 */
public class FlightList implements Serializable{
    int size;
    int[] flightIds;
    public FlightList(){
        
    }
    public FlightList(List<Flight> fl){
        size = fl.size();
        flightIds = new int[fl.size()];
        for(int i=0;i<flightIds.length; i++){
            flightIds[i] = fl.get(i).id;
        }
    }
    public int serialize(byte[] buffer, int offset) {
        System.out.println("FlightList serialize offset="+offset);
        offset = Serialization.putInt(size, buffer, offset);
        for(int i=0; i<flightIds.length; i++){
            offset = Serialization.putInt(flightIds[i],buffer,offset);
        }
        return offset;
    }

   

    public int deserialize(byte[] buffer, int offset) {
         //System.out.println("FlightList deserialize offset="+offset);
        MutableInteger in = new MutableInteger();
        offset = Serialization.getInt(in, buffer, offset);
        size = in.getValue();
        //System.out.println("FlightList deserialize size = " + size);
        flightIds = new int[size];
        for(int i=0; i<size; i++){
            offset = Serialization.getInt(in, buffer, offset);
            flightIds[i] = in.getValue();
        }
        return offset;
    }

    public String toString(){
        String t ="Flight Ids List: ";
        for (int i=0; i< size; i++){
            t +=  flightIds[i]+" ";
        }
        return t;
    }

}
